#ifndef AUDIOTHREAD_H
#define AUDIOTHREAD_H

#include <QThread>
#include "decodepacket.h"
#include <list>
#include <QAudioSink>
#include "resample.h"

namespace wxb{
class AudioThread : public QThread
{
public:
    explicit AudioThread(QObject *parent = nullptr);
    ~AudioThread();

public:
    void addPktToCache(AVPacket* pkt);
    void run() override;
    bool openDecoder(AVCodecParameters* params);

private:
    bool initQtPlay();
    bool initResample();

private:
    bool exitFlag = false;
    std::list<AVPacket*> pktList;

    AVCodecParameters* params = nullptr;
    DecodePacket decode;
    Resample* resample = nullptr;
    int sampleRate;
    int channelCount;

    QAudioSink* sink = nullptr;
    QIODevice* ioDevice = nullptr;
};
}

#endif // AUDIOTHREAD_H
